package com.hsteach.web.controller.buildingApply;

import com.google.common.collect.Maps;
import com.hsteach.common.core.controller.BaseController;
import com.hsteach.common.core.domain.AjaxResult;
import com.hsteach.common.core.domain.model.AuthInfo;
import com.hsteach.common.core.page.TableDataInfo;
import com.hsteach.common.utils.SecurityUtils;
import com.hsteach.dao.domain.buildingApply.BuildingReviewPerson;
import com.hsteach.enums.ApplyTypeEnum;
import com.hsteach.service.buildingApply.BuildingReviewPersonService;
import com.hsteach.web.controller.buildingApply.dto.ListBuildingReviewPersonDto;
import com.hsteach.web.controller.buildingApply.dto.UpdateBuildingReviewPersonDto;
import com.hsteach.web.controller.buildingApply.vo.ListBuildingReviewPersonVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 场馆申请审核人员配置Controller
 * 
 * @author fanxquer
 * @date 2023-08-27
 */
@Api(value = "场馆申请审核人员配置", tags = "场馆申请审核人员配置")
@RestController
@RequestMapping("/buildingApply/config")
public class BuildingReviewPersonController extends BaseController
{
    @Autowired
    private BuildingReviewPersonService buildingReviewPersonService;

    /**
     * 查询场馆申请审核人员配置列表
     */
    @ApiOperation("查询场馆申请审核人员配置列表")
    @PostMapping("/list")
    public TableDataInfo list(@RequestBody ListBuildingReviewPersonDto dto)
    {
        List<ListBuildingReviewPersonVo> list = buildingReviewPersonService.listBuildingReviewPerson(dto, ApplyTypeEnum.BUILDING);
        return getDataTable(list);
    }

    /**
     * 修改场馆申请审核人员配置
     */
    @ApiOperation("配置审核人员")
    @PutMapping
    public AjaxResult edit(@RequestBody UpdateBuildingReviewPersonDto dto)
    {
        return toAjax(buildingReviewPersonService.updatePerson(dto, ApplyTypeEnum.BUILDING));
    }

    /**
     * 查询当前用户是否为审核人员
     */
    @ApiOperation("查询当前用户是否为审核人员")
    @GetMapping("/isReviewer")
    public AjaxResult isReviewer()
    {
        AuthInfo authInfo = SecurityUtils.getAuthInfo();
        BuildingReviewPerson query = new BuildingReviewPerson();
        query.setReviewPersonId(authInfo.getPersonId());
        query.setOrgCode(authInfo.getOrgCode());
        query.setApplyType(ApplyTypeEnum.BUILDING.getCode());
        List<BuildingReviewPerson> buildingReviewPeople = buildingReviewPersonService.selectBuildingReviewPersonList(query);
        Map<String, Object> ret = Maps.newHashMap();
        if (CollectionUtils.isNotEmpty(buildingReviewPeople)) {
            ret.put("isReviewer", true);
        } else {
            ret.put("isReviewer", false);
        }
        return AjaxResult.success(ret);
    }

    /**
     * 删除场馆申请审核人员配置
     */
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(buildingReviewPersonService.deleteBuildingReviewPersonByIds(ids));
    }
}
